Next | Prev | Up | Top | Contents | Index

Support for CLONE Drivers

STREAMS Modules and Drivers, UNIX SVR4.2 discusses CLONE drivers; that is, STREAMS drivers that generate a new minor device number for each open. Refer to Chapter 3, "The CLONE Driver," and to Chapter 8, "Cloning." Clone opens and the clone driver are implemented under IRIX; this section clarifies the discussion in the SVR4 manual.

The essence of cloned access to a STREAMS driver is that the user process is indifferent to the minor device number, and simply wants to open a stream from this driver. A cloned stream is created using the following steps:

  1. Recognize that the process calling open() is indifferent to the minor device number and simply wants cloned access.

  2. Choose an unused minor device number from the set of minor numbers the driver supports.

  3. Construct a new device number dev_t value based on the chosen minor number, and assign it to the argument passed to pfxopen().

Using the CLONE Driver

The IRIX-supplied clone driver automates some of these steps for your driver. In order to use it, prepare a device special file with these characteristics:

You can view the descriptive file for the clone driver in /var/sysgen/master.d/clone. This file sets its major number (10) and states that it is not loadable. Although the clone driver is not specifically configured in the /var/sysgen/system/irix.sm file, it is included in any kernel because it is listed as a dependency in the descriptive file of several other drivers (use fgrep clone /var/sysgen/master.d/* to see which drivers depend on it; and see "Listing Dependencies"). You can specify it as a dependency in the same way, if your driver depends on it.

When a user process opens a device special file with the major number of the clone driver, the kernel naturally calls the clone driver's open entry point. The clone driver verifies that the minor number passed is the major number of an existing, STREAMS driver. (If it is not, the clone driver returns ENXIO).

The clone driver sets up the qinit structure appropriately for the target driver's queue and calls that driver's pfxopen() entry point, passing the CLONEOPEN flag in the sflag argument (see "Entry Point open()").


Recognizing a Clone Request Independently

It is not essential to use the clone driver. You can instead designate a particular minor device number to stand for "clone open." You prepare a device special file with these characteristics:

When a user process opens this device special file, the kernel calls the pfxopen() entry point of your driver. It does not pass the CLONEOPEN flag in sflag, but your driver can recognize a request for a clone open based on the minor device number.


Responding to a Clone Request

In response to a clone request coming from either of the two methods described, your pfxopen() entry point must select an unused minor device number. (If no minor number is available, return EBUSY.)

Text in Chapter 3 of STREAMS Modules and Drivers, UNIX SVR4.2 seems to suggest that your driver should scan through the kernel's cdevsw table to find an unused minor number (see "Kernel Switch Tables"). Under IRIX, the cdevsw table is not accessible to drivers. The reason is that the table layout differs between 32-bit and 64-bit kernels, and can change between releases. Instead, your driver must know the minor numbers that it supports, and must know which ones are currently in use.

Tip: You can design your driver so that the number of supported devices is specified in the descriptive file in /var/sysgen/master.d, and passed in to the driver through that descriptive file (see "Variables Section"). Your driver can allocate and initialize an array of device information structures in its pfxinit() entry point. Your driver constructs a new dev_t value, specifying its major number and the selected minor number. The makedevice() function is used for this (see the makedevice(D3) reference page, which has some sample code for use in a clone open). The new dev_t value is stored into the *devp argument passed to pfxopen().


Next | Prev | Up | Top | Contents | Index